package top.huntwolf.admin.common.enums;

public class CodeMsg {

    private int code;
    private String msg;

    //通用异常
    public static CodeMsg SUCCESS=new CodeMsg(200,"success");
    public static CodeMsg SERVER_ERROR=new CodeMsg(500100,"服务端异常:%s");
    public static CodeMsg BIND_ERROR=new CodeMsg(500101,"参数校验异常:%s");
    public static CodeMsg REQUEST_ILLEGAL=new CodeMsg(500102,"非法请求:%s");
    public static CodeMsg ACCESS_LIMIT=new CodeMsg(500103,"达到访问限制次数，访问太频繁!");
    public static CodeMsg METHOD_NOT_SUPPORT=new CodeMsg(500104,"请求方法不支持");
    public static CodeMsg CONTENT_TYPE_ERROR =new CodeMsg(500105,"Content-type错误:%s");
    public static CodeMsg NOT_FOUNT=new CodeMsg(500106,"未知的运行时异常");
    public static CodeMsg EXCEED_UPLOAD_SIZE=new CodeMsg(500107,"文件大小超过6M");
    public static CodeMsg NO_SUCH_ALGORITHM=new CodeMsg(500108,"当前不支持次算法:%s");
    public static CodeMsg INVALID_KEY=new CodeMsg(500109,"无效私钥");
    public static CodeMsg SIGNATURE_ERROR=new CodeMsg(500110,"签名计算失败");
    public static CodeMsg VALIDATION_ERROR=new CodeMsg(500111,"验证错误");
    public static CodeMsg PARSE_ERROR=new CodeMsg(500112,"解析错误");
    public static CodeMsg YQM_STORE_ERROR=new CodeMsg(500113,"yqm-store错误:%s");


    //登录模块异常
    public static CodeMsg SESSION_ERROR=new CodeMsg(500200,"session失效!");
    public static CodeMsg SIGNATURE_ILLEGAL=new CodeMsg(500201,"签名校检失败");
    public static CodeMsg WRONG_PASSWORD=new CodeMsg(500202,"密码错误");
    public static CodeMsg TOKEN_NOT_EXIST=new CodeMsg(500203,"无token，无权访问");
    public static CodeMsg IP_FREEZE=new CodeMsg(500204,"账号已冻结");

    //业务模块异常
    public static CodeMsg ORDER_TYPE_STATUS_NOT_MATCH=new CodeMsg(500300,"订单状态与订单类型不符");
    public static CodeMsg ORDER_NOT_EXIST=new CodeMsg(500301,"订单不存在");
    public static CodeMsg ISBN_INVALID=new CodeMsg(500302,"isbn不合法");
    public static CodeMsg USER_NOT_FOUND=new CodeMsg(500303,"用户不存在");
    public static CodeMsg ORDER_CANCEL_FAIL =new CodeMsg(500304,"订单取消失败");
    public static CodeMsg ITEM_NOT_EXIST =new CodeMsg(500305,"商品项不存在");
    public static CodeMsg ITEM_DELETE_FAIL =new CodeMsg(500306,"删除商品项失败");
    public static CodeMsg ITEM_HAS_EXIST =new CodeMsg(500307,"商品项已存在");
    public static CodeMsg ITEM_INSERT_FAIL =new CodeMsg(500308,"商品项增加失败");
    public static CodeMsg ITEM_UPDATE_FAIL =new CodeMsg(500309,"商品项更新失败");
    public static CodeMsg READ_EXCEL_ERROR =new CodeMsg(500310,"读取excel表添加数据异常");
    public static CodeMsg NON_FIND_SUBJECT =new CodeMsg(500311,"该分类暂时还没有书本请联系管理员添加");
    public static CodeMsg PARAMETER_NULL =new CodeMsg(500312,"参数为空，请检查参数传递");
    public static CodeMsg NOT_FIND_TOPICAL =new CodeMsg(500313,"还没得专题图书");
    public static CodeMsg NOT_FIND_ISBN =new CodeMsg(500314,"订单isbn为空");
    public static CodeMsg REPEATED_CART_ITEM = new CodeMsg(500315,"该购物车项目已存在");
    public static CodeMsg NOT_DISCOUNT = new CodeMsg(500316,"该折扣不存在");
    public static CodeMsg NOT_BUY_BOOK= new CodeMsg(500317,"书店没有此书");
    public static CodeMsg DUPLICATE_ADDRESS = new CodeMsg(500318,"地址已存在");
    public static CodeMsg MAX_PAGES = new CodeMsg(500319,"没有更多内容");
    public static CodeMsg REPEATED_BOOK = new CodeMsg(500320,"已存在本书籍");
    public static CodeMsg GIST_TOO_LONG= new CodeMsg(500321,"书本简介过长 %s");
    public static CodeMsg WRONG_BOOK_CONDITION= new CodeMsg(500322,"书本品相错误");
    public static CodeMsg ITEM_EXCEED= new CodeMsg(500323,"书本数量超出上限,具体书本isbn为:%s");
    public static CodeMsg ROLE_REPEAT= new CodeMsg(500324,"当前用户角色已为:%s");
    public static CodeMsg BOOK_UPDATE_FAIL= new CodeMsg(500325,"书本更新失败");
    public static CodeMsg DATABASE_ERROR= new CodeMsg(500326,"数据库错误：%s");
    public static CodeMsg ORDER_STATUS_ERROR= new CodeMsg(500327,"订单状态错误");
    public static CodeMsg STORAGE_ID_NON_EXIST= new CodeMsg(500328,"库存id不存在");
    public static CodeMsg ORIGIN_NOT_ENOUGH= new CodeMsg(500329,"原库存不足");
    public static CodeMsg USER_NAME_EXISTS= new CodeMsg(500310,"用户名已存在");
    public static CodeMsg ORDER_EXPIRATION= new CodeMsg(500311,"订单已过期");
    public static CodeMsg BOOK_TRANSFER_ERROR= new CodeMsg(500312,"商品转移错误");
    public static CodeMsg ADD_ROLE_ERROR = new CodeMsg(500313,"添加角色失败:%s");
    public static CodeMsg ADD_USER_ROLE_ERROR = new CodeMsg(500314,"用户添加角色失败:%s");
    public static CodeMsg ADD_ROLE_PERMISSION_ERROR = new CodeMsg(500315,"角色添加权限失败:%s");
    public static CodeMsg DELETE_USER_ROLE_ERROR = new CodeMsg(500316,"用户删除角色失败:%s");
    public static CodeMsg USER_NOT_EXIST = new CodeMsg(500317,"用户不存在");


    //易源接口模块异常
    public static CodeMsg SHOWAPI_ERROR=new CodeMsg(500400,"易源接口调用失败:%s");
    public static CodeMsg WXPAY_ERROR= new CodeMsg(500327,"微信支付调用失败:%s");
//    public static CodeMsg BOOK_NOT_FOUND = new CodeMsg(500301,"没有找到相关书籍");




    //todo:完善异常处理
    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    //返回一个带参数的错误码
    public CodeMsg fillArgs(Object...args){
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code,message);
    }

    @Override
    public String toString() {
        return "CodeMsg[code = " + code + ", msg = " + msg + "]";
    }
}
